<!--
 * @Author: ylyu
 * @Date: 2024-02-04 12:05:29
 * @LastEditors: ylyu
 * @LastEditTime: 2024-02-24 17:35:01
 * @Description: 
-->
<template>
  <div id="vueui-login-window">
    <div class="block-1">
      <div
        style="
          display: flex;
          justify-content: center;
          align-items: center;
          margin-bottom: 10px;
        "
      >
        <img src="../../../assets/douyin.png" width="55" />
        <h2 class="title">AI智能场控</h2>
      </div>
      <a>
        <a-form
          ref="loginForm"
          :model="userInfo"
          class="login-form"
          layout="vertical"
          @submit="handleSubmit"
        >
          <a-form-item
            field="username"
            :rules="[{ required: true, message: '请输入账号' }]"
            :validate-trigger="['change', 'blur']"
            hide-label
          >
            <a-input v-model="userInfo.username" placeholder="账号">
              <template #prefix>
                <icon-font type="icon-user" />
              </template>
            </a-input>
          </a-form-item>
          <a-form-item
            field="password"
            :rules="[{ required: true, message: '请输入密码' }]"
            :validate-trigger="['change', 'blur']"
            hide-label
          >
            <a-input-password v-model="userInfo.password" placeholder="密码">
              <template #prefix>
                <icon-font type="icon-lock-fill" />
              </template>
            </a-input-password>
          </a-form-item>
          <a-form-item field="rememberMe" hide-label>
            <a-checkbox v-model="userInfo.rememberMe">记住密码</a-checkbox>
          </a-form-item>
          <a-button type="primary" html-type="submit" :loading="loading">
            登 录
          </a-button>
        </a-form>
      </a>
    </div>
  </div>
</template>
<script>
import { ipcApiRoute } from '@/utils/ipcMainApi'
import { ipc } from '@/utils/ipcRenderer'
import { readConfig } from '@/utils/getConfig'
import { checkLogin } from '@/services'
export default {
  data() {
    return {
      loading: false,
      loginText: '正在登陆......',
      userInfo: {
        username: 'admin',
        password: '1qaz@WSX',
        rememberMe: true,
      },
    }
  },
  methods: {
    async handleSubmit({ values, errors }) {
      // console.log('error===', values, errors)
      if (!errors) {
        this.loading = true
        try {
          // console.log('111-------111')
          const res = await checkLogin({
            ...this.userInfo,
            rememberMe: true,
          })
          // console.log('登录ok=', res)
          this.$router.push({ name: 'Framework', params: {} })
          var { MainWinWidth, MainWinHeight, MainwindowTitle } =
            await readConfig()
          ipc
            .invoke('effect-restoreWindow', {
              width: MainWinWidth,
              height: MainWinHeight,
              windowTitle: MainwindowTitle,
            })
            .then((r) => {})
        } catch (error) {
          this.loading = false
          this.$message.error(error)
          console.log('登录失败：', error)
        }
        // setTimeout(async () => {
        //   this.$router.push({ name: 'Framework', params: {} })
        //   var { MainWinWidth, MainWinHeight, MainwindowTitle } =
        //     await readConfig()
        //   ipc
        //     .invoke(ipcApiRoute.restoreWindow, {
        //       width: MainWinWidth,
        //       height: MainWinHeight,
        //       windowTitle: MainwindowTitle,
        //     })
        //     .then((r) => {})
        // }, 1000)
      }
    },
  },
}
</script>
<style lang="less" scoped>
#vueui-login-window {
  width: 100%;
  min-height: 100%;
  background: var(--color-menu-dark-bg);
  display: flex;
  .block-1 {
    font-size: 16px;
    align-items: center;
    margin: auto;
    display: inline-block;
    color: var(--color-menu-light-bg);
  }
  .login-form {
    :deep(.arco-checkbox-label) {
      color: var(--color-menu-light-bg) !important;
    }
  }
  .title {
    padding-left: 10px;
  }
}
</style>
